function mxToolbar(container)
{
	this.container = container;
};
mxToolbar.prototype = new mxEventSource();
mxToolbar.prototype.constructor = mxToolbar;
mxToolbar.prototype.container = null;
mxToolbar.prototype.enabled = true;
mxToolbar.prototype.noReset = false;
mxToolbar.prototype.updateDefaultMode = true;
mxToolbar.prototype.addItem = function(title, icon, funct, pressedIcon, style, factoryMethod)
{
	var img = document.createElement((icon != null) ? 'img' : 'button');
	var initialClassName = style || ((factoryMethod != null) ? 'mxToolbarMode' : 'mxToolbarItem');
	img.className = initialClassName;
	img.setAttribute('src', icon);

	if (title != null)
	{
		if (icon != null)
		{
			img.setAttribute('title', title);
		}
		else
		{
			mxUtils.write(img, title);
		}
	}
	this.container.appendChild(img);

	if (funct != null)
	{
		mxEvent.addListener(img, 'click', funct);
	}
	var self = this;

	mxEvent.addListener(img, 'mousedown', function(evt)
	{
		if (pressedIcon != null)
		{
			img.setAttribute('src', pressedIcon);
		}
		else
		{
			img.style.backgroundColor = 'gray';
		}

		if (factoryMethod != null)
		{
			if (self.menu == null)
			{
				self.menu = new mxPopupMenu();
				self.menu.init();
			}
			var last = self.currentImg;

			if (self.menu.isMenuShowing())
			{
				self.menu.hideMenu();
			}

			if (last != img)
			{
				self.currentImg = img;
				self.menu.factoryMethod = factoryMethod;
				var point = new mxPoint(img.offsetLeft, img.offsetTop + img.offsetHeight);
				self.menu.popup(point.x, point.y, null, evt);

				if (self.menu.isMenuShowing())
				{
					img.className = initialClassName + 'Selected'
					self.menu.hideMenu = function()
					{
						mxPopupMenu.prototype.hideMenu.apply(this);
						img.className = initialClassName;
						self.currentImg = null;
					};
				}
			}
		}
	});
	var mouseHandler = function(evt)
	{
		if (pressedIcon != null)
		{
			img.setAttribute('src', icon);
		}
		else
		{
			img.style.backgroundColor = '';
		}
	}
	mxEvent.addListener(img, 'mouseup', mouseHandler);
	mxEvent.addListener(img, 'mouseout', mouseHandler);
	return img;
};
mxToolbar.prototype.addCombo = function(style)
{
	var div = document.createElement('div');
	div.style.display = 'inline';
	div.className = 'mxToolbarComboContainer';
	var select = document.createElement('select');
	select.className = style || 'mxToolbarCombo';
	div.appendChild(select);
	this.container.appendChild(div);
	return select;
};
mxToolbar.prototype.addActionCombo = function(title, style)
{
	var select = document.createElement('select');
	select.className = style || 'mxToolbarCombo';
	this.addOption(select, title, null);
	mxEvent.addListener(select, 'change', function(evt)
	{
		var value = select.options[select.selectedIndex];
		select.selectedIndex = 0;

		if (value.funct != null)
		{
			value.funct(evt);
		}
	});
	this.container.appendChild(select);
	return select;
};
mxToolbar.prototype.addOption = function(combo, title, value)
{
	var option = document.createElement('option');
	mxUtils.writeln(option, title);

	if (typeof (value) == 'function')
	{
		option.funct = value;
	}
	else
	{
		option.setAttribute('value', value);
	}
	combo.appendChild(option);
	return option;
};
mxToolbar.prototype.addSwitchMode = function(title, icon, funct, pressedIcon, style)
{
	var img = document.createElement('img');
	img.initialClassName = style || 'mxToolbarMode';
	img.className = img.initialClassName;
	img.setAttribute('src', icon);
	img.altIcon = pressedIcon;

	if (title != null)
	{
		img.setAttribute('title', title);
	}
	var self = this;
	mxEvent.addListener(img, 'click', function(evt)
	{
		var tmp = self.selectedMode.altIcon;

		if (tmp != null)
		{
			self.selectedMode.altIcon = self.selectedMode.getAttribute('src');
			self.selectedMode.setAttribute('src', tmp);
		}
		else
		{
			self.selectedMode.className = self.selectedMode.initialClassName;
		}

		if (self.updateDefaultMode)
		{
			self.defaultMode = img;
		}
		self.selectedMode = img;
		var tmp = img.altIcon;

		if (tmp != null)
		{
			img.altIcon = img.getAttribute('src');
			img.setAttribute('src', tmp);
		}
		else
		{
			img.className = img.initialClassName + 'Selected';
		}
		self.fireEvent(mxEvent.SELECT, new mxEventObject([null]));
		funct();
	});
	this.container.appendChild(img);

	if (this.defaultMode == null)
	{
		this.defaultMode = img;
		this.selectedMode = img;
		var tmp = img.altIcon;

		if (tmp != null)
		{
			img.altIcon = img.getAttribute('src');
			img.setAttribute('src', tmp);
		}
		else
		{
			img.className = img.initialClassName + 'Selected';
		}
		funct();
	}
	return img;
};
mxToolbar.prototype.addMode = function(title, icon, funct, pressedIcon, style)
{
	var img = document.createElement('img');
	img.initialClassName = style || 'mxToolbarMode';
	img.className = img.initialClassName;
	img.setAttribute('src', icon);
	img.altIcon = pressedIcon;

	if (title != null)
	{
		img.setAttribute('title', title);
	}

	if (this.enabled)
	{
		var self = this;
		mxEvent.addListener(img, 'click', function(evt)
		{
			self.selectMode(img, funct);
			self.noReset = false;
		});
		mxEvent.addListener(img, 'dblclick', function(evt)
		{
			self.selectMode(img, funct);
			self.noReset = true;
		});

		if (this.defaultMode == null)
		{
			this.defaultMode = img;
			this.selectedMode = img;
			var tmp = img.altIcon;

			if (tmp != null)
			{
				img.altIcon = img.getAttribute('src');
				img.setAttribute('src', tmp);
			}
			else
			{
				img.className = img.initialClassName + 'Selected';
			}
		}
	}
	this.container.appendChild(img);
	return img;
};
mxToolbar.prototype.selectMode = function(domNode, funct)
{
	if (this.selectedMode != domNode)
	{
		var tmp = this.selectedMode.altIcon;

		if (tmp != null)
		{
			this.selectedMode.altIcon = this.selectedMode.getAttribute('src');
			this.selectedMode.setAttribute('src', tmp);
		}
		else
		{
			this.selectedMode.className = this.selectedMode.initialClassName;
		}
		this.selectedMode = domNode;
		var tmp = this.selectedMode.altIcon;

		if (tmp != null)
		{
			this.selectedMode.altIcon = this.selectedMode.getAttribute('src');
			this.selectedMode.setAttribute('src', tmp);
		}
		else
		{
			this.selectedMode.className = this.selectedMode.initialClassName + 'Selected';
		}
		this.fireEvent(mxEvent.SELECT, new mxEventObject([funct]));
	}
};
mxToolbar.prototype.resetMode = function(forced)
{
	if ((forced || !this.noReset) && this.selectedMode != this.defaultMode)
	{
		this.selectMode(this.defaultMode, null);
	}
};
mxToolbar.prototype.addSeparator = function(icon)
{
	return this.addItem(null, icon, null);
};
mxToolbar.prototype.addBreak = function()
{
	mxUtils.br(this.container);
};
mxToolbar.prototype.addLine = function()
{
	var hr = document.createElement('hr');
	hr.style.marginRight = '6px';
	hr.setAttribute('size', '1');
	this.container.appendChild(hr);
};
mxToolbar.prototype.destroy = function()
{
	mxEvent.release(this.container);
	this.container = null;
	this.defaultMode = null;
	this.selectedMode = null;

	if (this.menu != null)
	{
		this.menu.destroy();
	}
};

function mxPopupMenu(factoryMethod)
{
	this.factoryMethod = factoryMethod;
};
mxPopupMenu.prototype.submenuImage = mxClient.imageBasePath + 'submenu.gif';
mxPopupMenu.prototype.zIndex = 10006;
mxPopupMenu.prototype.factoryMethod = true;
mxPopupMenu.prototype.useLeftButtonForPopup = false;
mxPopupMenu.prototype.enabled = true;
mxPopupMenu.prototype.itemCount = 0;
mxPopupMenu.prototype.init = function()
{
	this.table = document.createElement('table');
	this.table.className = 'mxPopupMenu';
	this.tbody = document.createElement('tbody');
	this.table.appendChild(this.tbody);
	this.div = document.createElement('div');
	this.div.className = 'mxPopupMenu';
	this.div.style.display = 'inline';
	this.div.style.zIndex = this.zIndex;
	this.div.appendChild(this.table);

	if (!mxClient.IS_IE && mxClient.MENU_SHADOWS)
	{
		this.shadow = document.createElement('div');
		this.shadow.className = 'mxPopupMenuShadow';
		this.shadow.style.zIndex = this.zIndex - 1;
		mxUtils.setOpacity(this.shadow, 70);
	}
	else if (mxClient.IS_IE && !mxClient.MENU_SHADOWS)
	{
		this.div.style.filter = '';
	}
	mxEvent.disableContextMenu(this.div);
};
mxPopupMenu.prototype.isEnabled = function()
{
	return this.enabled;
};
mxPopupMenu.prototype.setEnabled = function(enabled)
{
	this.enabled = enabled;
};
mxPopupMenu.prototype.isPopupTrigger = function(me)
{
	return me.isPopupTrigger() || (this.useLeftButtonForPopup && mxEvent.isLeftMouseButton(me.getEvent()));
};
mxPopupMenu.prototype.addItem = function(title, image, funct, parent)
{
	parent = parent || this;
	this.itemCount++;
	var tr = document.createElement('tr');
	tr.className = 'mxPopupMenuItem';
	var col1 = document.createElement('td');
	col1.className = 'mxPopupMenuIcon';

	if (image != null)
	{
		var img = document.createElement('img');

		if (!mxClient.IS_IE)
		{
			if (this.loading == null)
			{
				this.loading = 0;
			}
			this.loading++;
			var self = this;
			var loader = function()
			{
				mxEvent.removeListener(img, 'load', loader);
				self.loading--;

				if (self.loading == 0)
				{
					self.showShadow();
				}
			};
			mxEvent.addListener(img, 'load', loader);
		}
		img.src = image;
		col1.appendChild(img);
	}
	tr.appendChild(col1);
	var col2 = document.createElement('td');
	col2.className = 'mxPopupMenuItem';
	mxUtils.write(col2, title);
	col2.align = 'left';
	tr.appendChild(col2);
	var col3 = document.createElement('td');
	col3.style.width = '10px';
	col3.style.paddingRight = '6px';
	tr.appendChild(col3);

	if (parent.div == null)
	{
		this.createSubmenu(parent);
	}
	parent.tbody.appendChild(tr);
	var self = this;
	mxEvent.addListener(tr, 'mousedown', function(evt)
	{
		self.eventReceiver = tr;

		if (parent.activeRow != tr && parent.activeRow != parent)
		{
			if (parent.activeRow != null && parent.activeRow.div.parentNode != null)
			{
				self.hideSubmenu(parent);
			}

			if (tr.div != null)
			{
				self.showSubmenu(parent, tr);
				parent.activeRow = tr;
			}
		}
		mxEvent.consume(evt);
	});
	mxEvent.addListener(tr, 'mouseup', function(evt)
	{
		if (self.eventReceiver == tr)
		{
			if (parent.activeRow != tr)
			{
				self.hideMenu();
			}

			if (funct != null)
			{
				funct(evt);
			}
		}
		self.eventReceiver = null;
		mxEvent.consume(evt);
	});
	mxEvent.addListener(tr, 'mousemove', function(evt)
	{
		if (parent.activeRow != tr && parent.activeRow != parent)
		{
			if (parent.activeRow != null && parent.activeRow.div.parentNode != null)
			{
				self.hideSubmenu(parent);
			}
		}

		if (mxClient.IS_IE)
		{
			tr.style.backgroundColor = '#000066';
			tr.style.color = 'white';
		}
	});

	if (mxClient.IS_IE)
	{
		mxEvent.addListener(tr, 'mouseout', function(evt)
		{
			tr.style.backgroundColor = '';
			tr.style.color = '';
		});
	}
	return tr;
};
mxPopupMenu.prototype.createSubmenu = function(parent)
{
	parent.table = document.createElement('table');
	parent.table.className = 'mxPopupMenu';
	parent.tbody = document.createElement('tbody');
	parent.table.appendChild(parent.tbody);
	parent.div = document.createElement('div');
	parent.div.className = 'mxPopupMenu';
	parent.div.style.position = 'absolute';
	parent.div.style.display = 'inline';
	parent.div.appendChild(parent.table);
	var img = document.createElement('img');
	img.setAttribute('src', this.submenuImage);
	td = parent.firstChild.nextSibling.nextSibling;
	td.appendChild(img);
};
mxPopupMenu.prototype.showSubmenu = function(parent, row)
{
	if (row.div != null)
	{
		row.div.style.left = (parent.div.offsetLeft + row.offsetLeft + row.offsetWidth - 1) + 'px';
		row.div.style.top = (parent.div.offsetTop + row.offsetTop) + 'px';
		document.body.appendChild(row.div);
		var left = parseInt(row.div.offsetLeft);
		var width = parseInt(row.div.offsetWidth);
		var b = document.body;
		var d = document.documentElement;
		var right = (b.scrollLeft || d.scrollLeft) + (b.clientWidth || d.clientWidth);

		if (left + width > right)
		{
			row.div.style.left = (parent.div.offsetLeft - width + ((mxClient.IS_IE) ? 6 : -6)) + 'px';
		}
		mxUtils.fit(row.div);
	}
};
mxPopupMenu.prototype.addSeparator = function(parent)
{
	parent = parent || this;
	var tr = document.createElement('tr');
	var col1 = document.createElement('td');
	col1.className = 'mxPopupMenuIcon';
	col1.style.padding = '0 0 0 0px';
	tr.appendChild(col1);
	var col2 = document.createElement('td');
	col2.style.padding = '0 0 0 0px';
	col2.setAttribute('colSpan', '2');
	var hr = document.createElement('hr');
	hr.setAttribute('size', '1');
	col2.appendChild(hr);
	tr.appendChild(col2);
	parent.tbody.appendChild(tr);
};
mxPopupMenu.prototype.popup = function(x, y, cell, evt)
{
	if (this.div != null && this.tbody != null && this.factoryMethod != null)
	{
		this.div.style.left = x + 'px';
		this.div.style.top = y + 'px';

		while (this.tbody.firstChild != null)
		{
			mxEvent.release(this.tbody.firstChild);
			this.tbody.removeChild(this.tbody.firstChild);
		}
		this.itemCount = 0;
		this.factoryMethod(this, cell, evt);

		if (this.itemCount > 0)
		{
			this.showMenu();
		}
	}
};
mxPopupMenu.prototype.isMenuShowing = function()
{
	return this.div.parentNode == document.body;
};
mxPopupMenu.prototype.showMenu = function()
{
	document.body.appendChild(this.div);
	mxUtils.fit(this.div);

	if (this.shadow != null)
	{
		if (!this.loading)
		{
			this.showShadow();
		}
	}
};
mxPopupMenu.prototype.showShadow = function()
{
	if (this.shadow != null && this.div.parentNode == document.body)
	{
		this.shadow.style.left = (parseInt(this.div.style.left) + 3) + 'px';
		this.shadow.style.top = (parseInt(this.div.style.top) + 3) + 'px';
		this.shadow.style.width = this.div.offsetWidth + 'px';
		this.shadow.style.height = this.div.offsetHeight + 'px';
		document.body.appendChild(this.shadow);
	}
};
mxPopupMenu.prototype.hideMenu = function()
{
	if (this.div != null)
	{
		if (this.div.parentNode != null)
		{
			this.div.parentNode.removeChild(this.div);
		}

		if (this.shadow != null)
		{
			if (this.shadow.parentNode != null)
			{
				this.shadow.parentNode.removeChild(this.shadow);
			}
		}
		this.hideSubmenu(this);
	}
};
mxPopupMenu.prototype.hideSubmenu = function(parent)
{
	if (parent.activeRow != null)
	{
		this.hideSubmenu(parent.activeRow);

		if (parent.activeRow.div.parentNode != null)
		{
			parent.activeRow.div.parentNode.removeChild(parent.activeRow.div);
		}
		parent.activeRow = null;
	}
};
mxPopupMenu.prototype.destroy = function()
{
	if (this.div != null)
	{
		mxEvent.release(this.div);

		if (this.div.parentNode != null)
		{
			this.div.parentNode.removeChild(this.div);
		}
		this.div = null;
	}

	if (this.shadow != null)
	{
		mxEvent.release(this.shadow);

		if (this.shadow.parentNode != null)
		{
			this.shadow.parentNode.removeChild(this.shadow);
		}
		this.shadow = null;
	}
};